import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
	state: {
		is_open_socket: false,
		unreadSum: 0,
		addfrinedSum:0
	},
	mutations: {
		socketState(sate, flag) {
			sate.is_open_socket = flag
		},
		unreadSum(sate, sum) {
			sate.unreadSum = sum
			if (sum === 0) {
				uni.removeTabBarBadge({
					index: 0
				})
				uni.hideTabBarRedDot({
					index: 0
				})
			} else if (sum > 99) {
				uni.showTabBarRedDot({
					index: 0
				})
				uni.setTabBarBadge({
					index: 0,
					text: '99+'
				})
			
			} else {
				uni.showTabBarRedDot({
					index: 0
				})
				uni.setTabBarBadge({
					index: 0,
					text: sum.toString()
				})
			
			}
		},
		unreadSumAdd(sate) {
			sate.unreadSum += 1
			if (sate.unreadSum === 0) {
				uni.removeTabBarBadge({
					index: 0
				})
				uni.hideTabBarRedDot({
					index: 0
				})
			} else if (sate.unreadSum > 99) {
				uni.showTabBarRedDot({
					index: 0
				})
				uni.setTabBarBadge({
					index: 0,
					text: '99+'
				})
			
			} else {
				uni.showTabBarRedDot({
					index: 0
				})
				uni.setTabBarBadge({
					index: 0,
					text: sate.unreadSum.toString()
				})
			}
		},
		addfrinedSum(sate, sum) {
			sate.addfrinedSum = sum
			if (sum === 0) {
				uni.removeTabBarBadge({
					index: 1
				})
				uni.hideTabBarRedDot({
					index: 1
				})
			} else if (sum > 99) {
				uni.showTabBarRedDot({
					index: 1
				})
				uni.setTabBarBadge({
					index: 1,
					text: '99+'
				})
			
			} else {
				uni.showTabBarRedDot({
					index: 1
				})
				uni.setTabBarBadge({
					index: 1,
					text: sum.toString()
				})
			
			}
		},
		addfrinedSumAdd(sate) {
			sate.addfrinedSum += 1
			if (sate.addfrinedSum === 0) {
				uni.removeTabBarBadge({
					index: 1
				})
				uni.hideTabBarRedDot({
					index: 1
				})
			} else if (sate.addfrinedSum > 99) {
				uni.showTabBarRedDot({
					index: 1
				})
				uni.setTabBarBadge({
					index: 1,
					text: '99+'
				})
			
			} else {
				uni.showTabBarRedDot({
					index: 1
				})
				uni.setTabBarBadge({
					index: 1,
					text: sate.addfrinedSum.toString()
				})
			}
		},
		
	}
})
